package com.dwxt.community.aiequipment.util;

import java.util.*;

/**
 * @program: intelligentcity
 * @description:
 * @author
 * @create: 2020/04/16
 */
public class ReplyBaseUtil {

    /**
     * 固定byte
     *
     * @param i
     * @return
     */
    private static int[] fixationBytes(int size) {
        int[] ints = new int[size];
        //固定起始码
        ints[0] = 66;
        ints[1] = 65;
        //长度
        ints[2] = DataHandler.low(size);
        ints[3] = DataHandler.high(size);
        //时间
        Calendar instance = Calendar.getInstance();
        //年
        ints[4] = Integer.parseInt(String.valueOf(instance.get(Calendar.YEAR)).substring(2));
        //月
        ints[5] = instance.get(Calendar.MONTH) + 1;
        //日
        ints[6] = instance.get(Calendar.DAY_OF_MONTH);
        //时
        ints[7] = instance.get(Calendar.HOUR_OF_DAY);
        //分
        ints[8] = instance.get(Calendar.MINUTE);
        //秒
        ints[9] = instance.get(Calendar.SECOND);
        return ints;
    }

    /**
     * 构建响应字节数组
     *
     * @param i
     * @return
     */
    public static int[] ok(int size) {
        return bulidCrcBaseResponseInts(size,0,0);
    }
    /**
     * 构建响应字节数组
     *
     * @param i
     * @return
     */
    public static int[] bulidBaseResponseInts(int size, int connectStatue, int  businessStatue) {
        //设置起始码和时间
        int[] ints = fixationBytes(size);
        //通讯状态
        ints[10] = connectStatue;
        ints[11] = businessStatue;
        return ints;
    }
    /**
     * 构建响应字节数组
     *
     * @param i
     * @return
     */
    public static int[] bulidCrcBaseResponseInts(int size, int connectStatue, int  businessStatue) {
        int[] ints = bulidBaseResponseInts(size, connectStatue, businessStatue);
        return DataHandler.buildCrcArr(ints);
    }

}
